package raft

// must be used within critical section
func (rf *Raft) Convert2Follower(term int) {
	rf.Role = FOLLOWER
	rf.currentTerm = term
	rf.votedFor = -1
	rf.persist()
	DPrintf("node[%d]: Convert To Follower ,term: %d", rf.me, term)
}

func (rf *Raft) doFollower() {
	if rf.killed() {
		return
	}
	rf.mu.Lock()
	defer rf.mu.Unlock()
	if rf.Role != FOLLOWER {
		return
	}
	//if timeout, turn to candidate
	if rf.IsTimeOut(rf.electionTimeStamp, rf.electionTimeout) {
		rf.Convert2Candidate(rf.currentTerm)
		return
	}
}
